/*
* Copyright (c) Huawei Technologies Co., Ltd. 2019-2019. All rights reserved.
* Description: Fitness Machine profile
* Author: l00357454
* Create: 2019-7-22
* For the segment type of multi-byte transmission,
* it is transmitted in the packet format of the little endian.
*
*/
#include "fitness_machine_field.h"

#ifndef BLE_FTMS_H_
#define BLE_FTMS_H_



typedef unsigned char hw_u8;
typedef signed char hw_s8;
typedef unsigned short hw_u16;
typedef signed short hw_s16;
typedef int hw_s32;
typedef unsigned int hw_u32;
//typedef long long hw_s64;
//typedef unsigned long long hw_u64;

#ifndef NULL
#define NULL 	0
#endif




/**
 * 读取Fitness Machine Feature
 * featureField和targetSettingFeatures 见枚举值:fitness_machine_feature的定义
 * 使用average_speed|total_distance设置能力集的支持情况
 * featureField和targetSettingFeatures 对应枚举值:fitness_machine_feature_properties的定义
 * permission:read
 * uuid为fitness_machine_uuids.h的GATT_UUID_FITNESS_MACHINE_FEATURE、
 *
 */
void FitnessMachineFeatureAccessWrite(hw_u32 featureField,hw_u32 targetSettingFeatures);


void BleStateSet(hw_u8 p_data);
void BleStateRequest(void);
/**
*  返回 蓝牙MTU大小
*/
int GetPDUSize(void);
void SetPDUSize(unsigned int mtu_size);
#ifdef HWGYM_CROSSTRAINER
/**
 * 向外发送椭圆机运动数据
 *
 * 参数：data 待发送的运动数据
 * 返回值：成功 0；其他 失败
 */
int CrossTrainerDataAccessNotify(CROSS_TRAINER_DATA_T* data);

#endif

#ifdef HWGYM_ROWER
/**
 * 向外发送划船机运动数据
 *
 * 参数：data 待发送的运动数据
 * 返回值：成功 0；其他 失败
 */
int RowerDataAccessNotify(ROWER_DATA_T* data);

#endif

#ifdef HWGYM_INDOORBIKE
/**
 * 向外发送单车运动数据
 *
 * 参数：data 待发送的运动数据
 * 返回值：成功 0；其他 失败
 */
int IndoorBikeDataAccessNotify(INDOOR_BIKE_DATA_T* data);
#endif

#ifdef HWGYM_TREADMILL
/**
 * read Treadmill Data
 * 读取设置好的运动数据，返回一个数组
 * uuid为fitness_machine_uuids.h的GATT_UUID_TREADMILL_DATA
 * Total Distance uint24
 *
 */
int TreadmillDataAccessNotify(TREADMILL_DATA_T *data_value);
#endif

void ModelWrite(hw_u8 *data_value, hw_u16 length);
void SpeedUnitslWrite(hw_u8 data_value);
void HardwareVersionWrite(hw_u8 *p_data, hw_u16 length);

void McuNotice(hw_u8 *p_data, hw_u16 length);
/**
 * 设置Training Status Characteristics 的trainingStatus
 * read and Notification suported
 * trainingStatus见枚举值training_status的定义，传递对应参数即可
 * uuid为fitness_machine_uuids.h的GATT_UUID_TRAINING_STATUS
 *
 */
void TrainingStatusAccessWrite(hw_u8 trainingStatus);

/**
 * 读取Supported Power Range
 * permission:read
 * param:最大最小值，及最低增量
 * uuid为fitness_machine_uuids.h的GATT_UUID_SUPPORT_POWER_RANGE
 */
void PowerRangeWrite(signed short minPower, signed short maxPower, unsigned short minIncrement);
/**
 * 读取Supported Speed Range
 * permission:read
 * param:最大最小值，及最低增量
 * uuid为fitness_machine_uuids.h的GATT_UUID_SUPPORT_SPEED_RANGE
 *
 */
void SpeedRangeWrite(hw_u16 minSpeed,hw_u16 maxSpeed,hw_u16 minIncrement);

/**
 * 读取Supported Inclination Range
 * permission:read
 * param:最大最小值，及最低增量
 * uuid为fitness_machine_uuids.h的GATT_UUID_SUPPORT_INCLINATION_RANGE
 *
 */
void InclinationRangeWrite(hw_s16 minInclination,hw_s16 maxInclination,hw_u16 minIncrement);

/**
 * 读取Supported Resistance Level Range
 * permission:read
 * param:最大最小值，及最低增量
 * uuid为fitness_machine_uuids.h的GATT_UUID_SUPPORT_RESISTANCE_LEVEL_RANGE
 *
 */
void ResistanceLevelRangeWrite(hw_s16 minLevel,hw_s16 maxLevel,hw_u16 minIncrement);


/**
 * 读取Supported Heart Rate Range
 * permission:read
 * param:最大最小值，及最低增量
 * uuid为fitness_machine_uuids.h的GATT_UUID_SUPPORT_HEART_RATE_RANGE
 *
 */
void HeartRateRangeWrite(hw_u8 minHeartRate,hw_u8 maxHeartRate,hw_u8 minIncrement);


/**
 * 解析client传递的Fitness Machine Control Point
 * Permission:Write, Indicate
 * 参数第一个字节为opCode命令,后面的都为参数，参数长度0-18个字节
 * opCode的命令定义见fitness_machine_control_point_operation_code
 * 使用Fitness Machine Control Point 控制Fitness Machine前，会先发送Op Code = 0x00进行权限请求
 * 通过后才能进行发送命令，否则Fitness Machine不响应
 * 以下三种情况会失去权限控制
 * 1、蓝牙断开 2、client发送Op Code = Reset 3、Fitness Machine发送Control Permission Lost 的Notification
 * uuid为fitness_machine_uuids.h的GATT_UUID_FITNESS_MACHINE_CONTROL_POINT
 *
 */
void FitnessMachineControlPointWrite(hw_u8 *pBuf,hw_u8 length);


/**
 * client传递的Fitness Machine Control Point 的response
 * 参数为该次Fitness Machine Control Point的结构体
 * 在命令执行后发送答复
 * uuid为fitness_machine_uuids.h的GATT_UUID_FITNESS_MACHINE_CONTROL_POINT
 * resultCode见枚举值fitness_machine_control_point_response_resultCode的定义
 *
 */
void FitnessMachineControlPointResponse(hw_u8 opCode,hw_u8 resultCode);



/**
 * Fitness Machine传递的Fitness Machine status
 * Permission:Notify
 * opCode见fitness_machine_status_operation_code的定义，parameter传递实际数值
 * uuid为fitness_machine_uuids.h的GATT_UUID_FITNESS_MACHINE_STATUS
 * 若为以下命令则有参数：target_speed_changed=0x05, // 参数范围：uint16
 * target_incline_changed=0x06, // 参数范围：sint16

 */
void FitnessMachineStatusnotify(hw_u8 opCode,hw_u8* parameter);


/**
 * Fitness Extension Data Characteristic for FTMS
 * 当前支持的数据类型见fitness_extension_data定义，
 * 具体字段的长度见huawei_fitness_extension_data_t
 * 函数将返回一个huawei_fitness_extension_data_t的结构体。
 * uuid为fitness_machine_uuids.h的GATT_UUID_FITNESS_EXTENSION_DATA
 *
 */
void fitnessExtensionDataWrite(hw_u8* pBuf,hw_u8 length);

/**
 * 蓝牙断开时需要重置标志位
 * 将会重置请求的控制权限和解锁码的校验状态
 * 在蓝牙断开回调的函数中调用该函数即可
 *
 */
void ResetWhenBluetoothDisconnect(void);
#endif /* BLE_FTMS_H_ */

